/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.restaurant.facade;

import com.restaurant.entities.Persons;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Dexter
 */
@Stateless
public class PersonsFacade extends AbstractFacade<Persons> implements PersonsFacadeLocal {
    @PersistenceContext(unitName = "com.restaurant_Restaurant_ZPHE-ejb_ejb_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PersonsFacade() {
        super(Persons.class);
    }
    
    @Override
    public void create(Persons entity) {
        getEntityManager().persist(entity);
    }
    
    @Override
    public void edit(Persons entity) {
        getEntityManager().merge(entity);
    }
    
    @Override
    public Persons getUserByLogin(String login) {
        return (Persons) em.createQuery("SELECT p FROM Persons p WHERE p.login = '"+ login +"'").getSingleResult();
    }

}
